<?php
namespace app\dk\admin;
use app\admin\controller\Admin;

use app\dk\model\Advertise as m_ad;
use think\Request;
use think\Db;

class Gg extends Admin
{
    public function index($q = '')
    {
        $map = [];
        if ($q) {
            // 用户名、昵称
                $map['name'] = ['like', '%'.$q.'%'];
        }
        
        $data_list = m_ad::where($map)->order('is_del asc')->paginate();
		
        // 分页
        $pages = $data_list->render();
        $this->assign('data_list', $data_list);
        $this->assign('pages', $pages);
        return $this->fetch();
    }
	
	
	public function add($id = 0)
    {
		
        if ($this->request->isPost()) {
            $data = $this->request->post();
			$data['is_one']=0;
			$data['is_del']=1;
            unset($data['id']);
			
            if (!m_ad::create($data)) {
                return $this->error('添加失败！');
            }
            return $this->success('添加成功。');
        }
		
        return $this->fetch('form');
    }
	
	
    public function edit($id = 0)
    {

        if ($this->request->isPost()) {
			
            $data = $this->request->post();
           
            if (!m_ad::update($data)) {
                return $this->error('修改失败！');
            }
            return $this->success('修改成功。');
        }
		
		$pm = $this->request->param();
		if(isset($pm["ql"])){
			$ql = $pm["ql"];
			if($ql == "gb"){
				Db::name('advertise')->where('id', $id)->update(['is_del' => 1]);
			}else{
				Db::name('advertise')->where('is_del', 0)->update(['is_del' => 1]);
				
				Db::name('advertise')->where('id', $id)->update(['is_del' => 0]);
			}
			
			return $this->success('修改成功');
		}
		

        $row = m_ad::where('id', $id)->find()->toArray();
        $this->assign('data_info', $row);
        return $this->fetch('form');
    }
	
	 
	
}